package com.example.shushiyunsst.fragment.main.mine.child

import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.example.library_common.base.BaseFragmentEx
import com.example.shushiyunsst.R
import com.google.android.material.tabs.TabLayout

/**
 * 修改密码
 * */
class ReSettingPassWordFragment : BaseFragmentEx() {
    companion object {
        fun newInstance(): ReSettingPassWordFragment {
            val args = Bundle()

            val fragment = ReSettingPassWordFragment()
            fragment.arguments = args
            return fragment
        }
    }

    private val pageLs = listOf<BaseFragmentEx>(
        ReSettingSignInPasswordFragment.newInstance(),
        ReSettingPayingPasswordFragment.newInstance()
    )

    override fun getLayoutId(): Any {
        return R.layout.re_setting_password_fragment
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val mToolbar: Toolbar = view.findViewById(R.id.mToolbar)
        mToolbar.title = "修改密码"
        mToolbar.setNavigationOnClickListener { onBackPressedSupport() }

        val mViewPager: ViewPager = view.findViewById(R.id.mViewPager)
        val mTabLayout: TabLayout = view.findViewById(R.id.mTabLayout)
        mViewPager.adapter = object : FragmentStatePagerAdapter
            (childFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int {
                return pageLs.size
            }

            override fun getItem(position: Int): Fragment {
                return pageLs[position]
            }

            override fun getPageTitle(position: Int): CharSequence? {
                val lab = getItem(position) as ReSettingPassWordLab
                return lab.labInfo
            }

        }
        mTabLayout.setupWithViewPager(mViewPager)
    }
}